package creational.pattern.factory.factories;

import creational.pattern.factory.beans.Bean;
import creational.pattern.factory.beans.Bean1;
import creational.pattern.factory.beans.Bean2;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author yoyuan
 * @Description: 注入bean的简单工厂，各个方法可以通过这个工厂获取对象
 * @DateTime: 2023/1/8 15:38
 */
public class BeanSimpleFactory {
    /**
     * beanMap类型为static final以及static代码段都对当前工厂设置了
     * 所有bean都需要设置好进行配置，之后不可添加，适合固定数量的产品
     * 可拓展的看BeanFactory
     */
    private static final Map<String, Bean> beanMap = new HashMap<>();
    static {
        beanMap.put("bean1", new Bean1());
        beanMap.put("bean2", new Bean2());
    }
    public Bean getBean(String beanName){
        return beanMap.get(beanName);
    }
}
